home *** CD-ROM | disk | FTP | other *** search
- #include <exec/types.h>
- #include <exec/nodes.h>
- #include <exec/lists.h>
- #include <exec/memory.h>
- #include <powerup/ppclib/interface.h>
- #include <powerup/ppclib/semaphore.h>
- #include <powerup/ppclib/message.h>
- #include <powerup/ppclib/tasks.h>
- #include <powerup/gcclib/powerup_protos.h>
- #include <stdio.h>
-
- /* This Taskcounter isn`t that smart
- */
- ULONG TaskCounter=0;
- void *Semaphore;
-
- #define TASKA_MSG "TaskA Good Morning"
- #define TASKB_MSG "TaskB Good Morning"
- #define TASKC_MSG "TaskC Good Morning"
- #define TASKD_MSG "TaskD Good Morning"
-
-
- void TaskA(void);
- void TaskB(void);
- void TaskC(void);
- void TaskD(void);
-
-
- int main(void)
- {
- void *Msg;
- void *ReplyPort;
- void *StartUpMsgA;
- void *StartUpMsgB;
- void *StartUpMsgC;
- void *StartUpMsgD;
- void *TaskObjectA;
- void *TaskObjectB;
- void *TaskObjectC;
- void *TaskObjectD;
- struct TagItem MyTags[10];
- ULONG MsgCounter;
- ULONG TaskStartCounter;
- int Status;
-
- Status = 20;
-
- MyTags[0].ti_Tag = TAG_DONE;
- if ((Semaphore=PPCCreateSemaphore(MyTags)))
- {
- MyTags[0].ti_Tag = TAG_DONE;
- if (ReplyPort = PPCCreatePort(MyTags))
- {
- if (StartUpMsgA = PPCCreateMessage(ReplyPort, sizeof(TASKA_MSG)))
- {
- if (StartUpMsgB = PPCCreateMessage(ReplyPort, sizeof(TASKB_MSG)))
- {
- if (StartUpMsgC = PPCCreateMessage(ReplyPort, sizeof(TASKC_MSG)))
- {
- if (StartUpMsgD = PPCCreateMessage(ReplyPort, sizeof(TASKD_MSG)))
- {
- /* Wait for 4 Startup Msg replies */
- MsgCounter = 4;
- TaskStartCounter= 0;
-
- MyTags[0].ti_Tag = PPCTASKTAG_STARTUP_MSG;
- MyTags[0].ti_Data =(ULONG) StartUpMsgA;
-
- MyTags[1].ti_Tag = PPCTASKTAG_STARTUP_MSGDATA;
- MyTags[1].ti_Data =(ULONG) TASKA_MSG;
-
- MyTags[2].ti_Tag = PPCTASKTAG_STARTUP_MSGLENGTH;
- MyTags[2].ti_Data = sizeof(TASKD_MSG);
-
- MyTags[3].ti_Tag = PPCTASKTAG_STARTUP_MSGID;
- MyTags[3].ti_Data = 0;
-
- MyTags[4].ti_Tag = PPCTASKTAG_MSGPORT;
- MyTags[4].ti_Data = TRUE;
-
- MyTags[5].ti_Tag = TAG_DONE;
-
- if (TaskObjectA=PPCCreateTask(NULL,
- &TaskA,
- MyTags))
- {
- TaskStartCounter++;
- PPCprintf("TaskObjectA 0x%lx created...\n",
- TaskObjectA);
-
- MyTags[0].ti_Tag = PPCTASKTAG_STARTUP_MSG;
- MyTags[0].ti_Data =(ULONG) StartUpMsgB;
-
- MyTags[1].ti_Tag = PPCTASKTAG_STARTUP_MSGDATA;
- MyTags[1].ti_Data =(ULONG) TASKB_MSG;
-
- MyTags[2].ti_Tag = PPCTASKTAG_STARTUP_MSGLENGTH;
- MyTags[2].ti_Data = sizeof(TASKD_MSG);
-
- MyTags[3].ti_Tag = PPCTASKTAG_STARTUP_MSGID;
- MyTags[3].ti_Data = 0;
-
- MyTags[4].ti_Tag = PPCTASKTAG_MSGPORT;
- MyTags[4].ti_Data = TRUE;
-
- MyTags[5].ti_Tag = TAG_DONE;
-
-
- if (TaskObjectB=PPCCreateTask(NULL,
- &TaskB,
- MyTags))
- {
- TaskStartCounter++;
- PPCprintf("TaskObjectB 0x%lx created...\n",
- TaskObjectB);
-
-
- MyTags[0].ti_Tag = PPCTASKTAG_STARTUP_MSG;
- MyTags[0].ti_Data =(ULONG) StartUpMsgC;
-
- MyTags[1].ti_Tag = PPCTASKTAG_STARTUP_MSGDATA;
- MyTags[1].ti_Data =(ULONG) TASKC_MSG;
-
- MyTags[2].ti_Tag = PPCTASKTAG_STARTUP_MSGLENGTH;
- MyTags[2].ti_Data = sizeof(TASKD_MSG);
-
- MyTags[3].ti_Tag = PPCTASKTAG_STARTUP_MSGID;
- MyTags[3].ti_Data = 0;
-
- MyTags[4].ti_Tag = PPCTASKTAG_MSGPORT;
- MyTags[4].ti_Data = TRUE;
-
- MyTags[5].ti_Tag = TAG_DONE;
-
- if (TaskObjectC=PPCCreateTask(NULL,
- &TaskC,
- MyTags))
- {
- TaskStartCounter++;
- PPCprintf("TaskObjectC 0x%lx created...\n",
- TaskObjectC);
-
- MyTags[0].ti_Tag = PPCTASKTAG_STARTUP_MSG;
- MyTags[0].ti_Data =(ULONG) StartUpMsgD;
-
- MyTags[1].ti_Tag = PPCTASKTAG_STARTUP_MSGDATA;
- MyTags[1].ti_Data =(ULONG) TASKD_MSG;
-
- MyTags[2].ti_Tag = PPCTASKTAG_STARTUP_MSGLENGTH;
- MyTags[2].ti_Data = sizeof(TASKD_MSG);
-
- MyTags[3].ti_Tag = PPCTASKTAG_STARTUP_MSGID;
- MyTags[3].ti_Data = 0;
-
- MyTags[4].ti_Tag = PPCTASKTAG_MSGPORT;
- MyTags[4].ti_Data = TRUE;
-
- MyTags[5].ti_Tag = TAG_DONE;
-
- if (TaskObjectD=PPCCreateTask(NULL,
- &TaskD,
- MyTags))
- {
- TaskStartCounter++;
- PPCprintf("TaskObjectD 0x%lx created...\n",
- TaskObjectD);
-
- while (TaskCounter<TaskStartCounter);
-
-
- PPCprintf("Waiting for Task Finish Msg...\n");
- for (;;)
- {
- Msg = PPCGetMessage(ReplyPort);
- if ((Msg == StartUpMsgA) ||
- (Msg == StartUpMsgB) ||
- (Msg == StartUpMsgC) ||
- (Msg == StartUpMsgD))
- {
- PPCprintf("Got StartUp Msg 0x%lx..\n",
- Msg);
- if (--MsgCounter <= 0)
- {
- break;
- }
- }
- else
- {
- PPCprintf("Some non replied or empty Msg 0x%lx was found..wait\n",
- Msg);
- PPCWaitPort(ReplyPort);
- }
- }
-
- Status = 0;
- }
- else
- {
- PPCprintf("Couldn`t Start Task D\n");
- }
- }
- else
- {
- PPCprintf("Couldn`t Start Task C\n");
- }
- }
- else
- {
- PPCprintf("Couldn`t Start Task B\n");
- }
- }
- else
- {
- PPCprintf("Couldn`t Start Task A\n");
- }
-
- /* Some trick to make sure the PPC tasks have been gone
- * This could be an alternative way to check for the exit
- * if you don`t wanna use the startup msg reply.
- */
- PPCObtainSemaphore(Semaphore);
- PPCReleaseSemaphore(Semaphore);
-
- PPCDeleteMessage(StartUpMsgD);
- }
- else
- {
- PPCprintf("Couldn`t create StartUpMsgD\n");
- }
- PPCDeleteMessage(StartUpMsgC);
- }
- else
- {
- PPCprintf("Couldn`t create StartUpMsgC\n");
- }
- PPCDeleteMessage(StartUpMsgB);
- }
- else
- {
- PPCprintf("Couldn`t create StartUpMsgB\n");
- }
- PPCDeleteMessage(StartUpMsgA);
- }
- else
- {
- PPCprintf("Couldn`t create StartUpMsgA\n");
- }
-
- while (PPCDeletePort(ReplyPort) == FALSE);
- }
- PPCDeleteSemaphore(Semaphore);
- }
- else
- {
- PPCprintf("Couldn`t create Semaphore\n");
- }
- return(Status);
- }
-
-
- void TaskA(void)
- {
- int i;
-
- PPCObtainSemaphoreShared(Semaphore);
- TaskCounter++;
-
- PPCprintf("TaskA StartUp Msg %s\n",
- PPCGetTaskAttr(PPCTASKTAG_STARTUP_MSGDATA));
-
- for (i=0;i<200;i++)
- {
- PPCprintf("TaskA: %ld\n",
- i);
- }
- PPCReleaseSemaphore(Semaphore);
- }
-
- void TaskB(void)
- {
- int i;
-
- PPCObtainSemaphoreShared(Semaphore);
- TaskCounter++;
-
- PPCprintf("TaskB StartUp Msg %s\n",
- PPCGetTaskAttr(PPCTASKTAG_STARTUP_MSGDATA));
-
- for (i=0;i<200;i++)
- {
- PPCprintf("TaskB: %ld\n",
- i);
- }
- PPCReleaseSemaphore(Semaphore);
- }
-
- void TaskC(void)
- {
- int i;
-
- PPCObtainSemaphoreShared(Semaphore);
- TaskCounter++;
-
- PPCprintf("TaskC StartUp Msg %s\n",
- PPCGetTaskAttr(PPCTASKTAG_STARTUP_MSGDATA));
-
- for (i=0;i<200;i++)
- {
- PPCprintf("TaskC: %ld\n",
- i);
- }
- PPCReleaseSemaphore(Semaphore);
- }
-
- void TaskD(void)
- {
- int i;
-
- PPCObtainSemaphoreShared(Semaphore);
- TaskCounter++;
-
- PPCprintf("TaskD StartUp Msg %s\n",
- PPCGetTaskAttr(PPCTASKTAG_STARTUP_MSGDATA));
-
- for (i=0;i<200;i++)
- {
- PPCprintf("TaskD: %ld\n",
- i);
- }
- PPCReleaseSemaphore(Semaphore);
- }
-